/**
 * 获得搜索参数
 * @param params
 * @returns {Object}
 */
function getSearchParams(params) {
    var searchParams = new Object();
    if (params != undefined) {
        searchParams = params;
    }
    $('.SearchForm').each(function() {
        var param = $(this).val().trim();
        if (param == undefined)
            param = '';
        searchParams[$(this).attr('name')] = param;
    });
    return searchParams;
}
//清空搜索条件
$("#Reset").click(function() {
    $('.SearchForm').val('');
});

/**
 * 页面自加载
 */
$(function() {
    var cellwidth = ($(".box-content.table-responsive").width() - 55) / 11;
    var psval = $('#datatable_ipinfo').attr('data-size');
    if (psval == undefined || psval == "") {
        psval = 10;
    }
    /**
     * easyui 生成表格数据
     */
    $('#datatable_ipinfo').datagrid({
        singleSelect: true, //允许选择多行
        striped: true,
        idField: 'id',
        remoteSort: false,
        collapsible: true,
        fit: false,
        url: 'admin/User/ips', //数据源路径
        loadMsg: '请等待数据载入....',
        pagination: true,
        rownumbers: true,
        fitColumns: true,
        pageSize: psval,
        pageList: [psval, psval * 2, psval * 3, psval * 4, psval * 5],
        columns: [[{
            field: 'id',
            title: '用户id',
            align: 'center',
            width: cellwidth,
            sortable: true
        }, {
            field: 'ip',
            title: '用户ip',
            align: 'center',
            width: cellwidth,
            sortable: true
        }, {
            field: 'type',
            title: '所属页面',
            align: 'center',
            width: cellwidth,
            sortable: true,
            formatter:function(value){
                if(value == 1){return 'wap短链接';}
                if(value == 2){return 'H5首页地球页';}
                if(value == 3){return 'H5视频观看页';}
                if(value == 4){return 'H5长图介绍页';}
                if(value == 5){return 'H5选择行为页';}
                if(value == 6){return 'H5生成图片页';}
                if(value == 7){return 'H5填写手机号页面';}
                if(value == 8){return 'H5生成专属密码';}
            }
        }, {
            field: 'from',
            title: '来源（渠道）',
            align: 'center',
            width: cellwidth,
            sortable: true,
            formatter:function(value){
                if(value == 'userSelf'){
                    return '用户访问';
                }else{
                    return value;
                }
            }
        }, {
            field: 'time',
            title: '访问时间',
            align: 'center',
            width: cellwidth,
            sortable: true
        }]],
        onBeforeLoad: function (param) {
            param = getSearchParams(param);
        },
    });
    /*搜索*/
    $('#Search').click(function () {
        $('#datatable_ipinfo').datagrid('reload');
    })
    
});